package cn.iocoder.yudao.module.agri.dal.mysql.company;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.agri.dal.dataobject.company.CompanyDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.agri.controller.admin.company.vo.*;

/**
 * 企业信息 Mapper
 *
 * @author 广东小蜂
 */
@Mapper
public interface CompanyMapper extends BaseMapperX<CompanyDO> {

    default PageResult<CompanyDO> selectPage(CompanyPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CompanyDO>()
                .eqIfPresent(CompanyDO::getId, reqVO.getId())
                .likeIfPresent(CompanyDO::getLegalName, reqVO.getLegalName())
                .likeIfPresent(CompanyDO::getAddress, reqVO.getAddress())
                .eqIfPresent(CompanyDO::getAuditStatus, reqVO.getAuditStatus())
                .eqIfPresent(CompanyDO::getSupply, reqVO.getSupply())
                .likeIfPresent(CompanyDO::getName, reqVO.getName())
                .eqIfPresent(CompanyDO::getBizType, reqVO.getBizType())
                .eqIfPresent(CompanyDO::getStatus, reqVO.getStatus())
                .eqIfPresent(CompanyDO::getType, reqVO.getType())
                .eqIfPresent(CompanyDO::getAreaId, reqVO.getAreaId())
                .likeIfPresent(CompanyDO::getLinkName, reqVO.getLinkName())
                .eqIfPresent(CompanyDO::getLinkTel, reqVO.getLinkTel())
                .eqIfPresent(CompanyDO::getLegalCode, reqVO.getLegalCode())
                .orderByDesc(CompanyDO::getId));
    }

    default List<CompanyDO> selectList(CompanyExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CompanyDO>()
                .eqIfPresent(CompanyDO::getId, reqVO.getId())
                .likeIfPresent(CompanyDO::getLegalName, reqVO.getLegalName())
                .likeIfPresent(CompanyDO::getAddress, reqVO.getAddress())
                .eqIfPresent(CompanyDO::getAuditStatus, reqVO.getAuditStatus())
                .eqIfPresent(CompanyDO::getSupply, reqVO.getSupply())
                .likeIfPresent(CompanyDO::getName, reqVO.getName())
                .eqIfPresent(CompanyDO::getBizType, reqVO.getBizType())
                .eqIfPresent(CompanyDO::getStatus, reqVO.getStatus())
                .eqIfPresent(CompanyDO::getType, reqVO.getType())
                .eqIfPresent(CompanyDO::getAreaId, reqVO.getAreaId())
                .likeIfPresent(CompanyDO::getLinkName, reqVO.getLinkName())
                .eqIfPresent(CompanyDO::getLinkTel, reqVO.getLinkTel())
                .eqIfPresent(CompanyDO::getLegalCode, reqVO.getLegalCode())
                .orderByDesc(CompanyDO::getId));
    }

    default CompanyDO getCompanyByTenant(){
        return selectTopOne(CompanyDO::getStatus,1,CompanyDO::getUpdateTime,false);
    }

}
